package com.b2b.util;

import com.b2b.model.QuotationListDto;
import com.b2b.model.entity.Inquiry;
import com.b2b.model.entity.InquiryQuotation;
import com.b2b.service.InquiryQuotationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class InquiryQuotationUtil {
    private final InquiryQuotationService inquiryQuotationService;
    private final InquiryUtil inquiryUtil;
    @Autowired
    public InquiryQuotationUtil(InquiryQuotationService inquiryQuotationService,InquiryUtil inquiryUtil){
        this.inquiryQuotationService = inquiryQuotationService;
        this.inquiryUtil = inquiryUtil;
    }

    public List<InquiryQuotation> getTry(Integer companyId){
        List<InquiryQuotation> inquiryQuotationList = inquiryQuotationService.selectQuotationGoodsByCompanyId(companyId);

        return inquiryQuotationList;
    }
    public Integer insertInquiryQuotation(QuotationListDto quotationListDto){
        InquiryQuotation inquiryQuotation = getInquiryQuotation(quotationListDto);
        Integer count = inquiryQuotationService.insert(inquiryQuotation);
        return count;
    }
    //    public List<InquiryQuotation> getInquiryQuotationByC(){
//
//    }
    public InquiryQuotation getInquiryQuotation(QuotationListDto quotationListDto){
        InquiryQuotation inquiryQuotation = new InquiryQuotation();
        inquiryQuotation.setInquiryId(quotationListDto.getInquiryId());
        inquiryQuotation.setQuotationId(quotationListDto.getQuotationId());
        return inquiryQuotation;
    }

    public List<InquiryQuotation> selectByInquiryId(Integer inquiryId){
        InquiryQuotation inquiryQuotation = new InquiryQuotation();
        inquiryQuotation.setInquiryId(inquiryId);
        List<InquiryQuotation> inquiryQuotationList = inquiryQuotationService.select(inquiryQuotation);
        return inquiryQuotationList;
    }

    public Inquiry getInquiryByQuotationId(Integer quotationId){
        Integer inquiryId = getInquiryId(quotationId);
        Inquiry inquiry = inquiryUtil.getInquiryByInquiryId(inquiryId);
        return inquiry;
    }
    public Integer getInquiryId(Integer quotationId){
        InquiryQuotation inquiryQuotation = new InquiryQuotation();
        inquiryQuotation.setQuotationId(quotationId);
        inquiryQuotation = inquiryQuotationService.selectOne(inquiryQuotation);
        Integer inquiryId = inquiryQuotation.getInquiryId();
        return inquiryId;
    }
    public Integer deleteInquiryQuotation(Integer quotationId){
        InquiryQuotation inquiryQuotation = new InquiryQuotation();
        inquiryQuotation.setQuotationId(quotationId);

        Integer result = inquiryQuotationService.delete(inquiryQuotation);

        return result;
    }
}
